<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <!-- 欢迎卡片 -->
      <el-col :span="24">
        <el-card class="welcome-card">
          <template #header>
            <div class="card-header">
              <span>欢迎回来</span>
            </div>
          </template>
          <div class="welcome-content">
            <el-avatar
              :size="64"
              :src="userInfo.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'"
            />
            <div class="welcome-info">
              <h3>{{ userInfo.name }}</h3>
              <p>管理员</p>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="mt-20">
      <!-- 数据统计卡片 -->
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <div class="data-header">
            <el-icon class="icon"><User /></el-icon>
            <div class="data-title">用户总数</div>
          </div>
          <div class="data-number">1,234</div>
          <div class="data-footer">
            <span class="trend up">
              <el-icon><ArrowUp /></el-icon>
              12%
            </span>
            <span class="compare">较上周</span>
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <div class="data-header">
            <el-icon class="icon"><ShoppingCart /></el-icon>
            <div class="data-title">订单数量</div>
          </div>
          <div class="data-number">856</div>
          <div class="data-footer">
            <span class="trend up">
              <el-icon><ArrowUp /></el-icon>
              8%
            </span>
            <span class="compare">较上周</span>
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <div class="data-header">
            <el-icon class="icon"><Money /></el-icon>
            <div class="data-title">销售额</div>
          </div>
          <div class="data-number">¥45,678</div>
          <div class="data-footer">
            <span class="trend down">
              <el-icon><ArrowDown /></el-icon>
              3%
            </span>
            <span class="compare">较上周</span>
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <div class="data-header">
            <el-icon class="icon"><View /></el-icon>
            <div class="data-title">访问量</div>
          </div>
          <div class="data-number">12,345</div>
          <div class="data-footer">
            <span class="trend up">
              <el-icon><ArrowUp /></el-icon>
              25%
            </span>
            <span class="compare">较上周</span>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 系统信息卡片 -->
    <el-row :gutter="20" class="mt-20">
      <el-col :span="24">
        <el-card class="system-card">
          <template #header>
            <div class="card-header">
              <span>系统信息</span>
            </div>
          </template>
          <el-descriptions :column="2" border>
            <el-descriptions-item label="系统名称">豆角云管理系统</el-descriptions-item>
            <el-descriptions-item label="当前版本">v1.0.0</el-descriptions-item>
            <el-descriptions-item label="服务器环境">CentOS 7.6</el-descriptions-item>
            <el-descriptions-item label="数据库版本">MySQL 8.0</el-descriptions-item>
            <el-descriptions-item label="Node版本">v16.0.0</el-descriptions-item>
            <el-descriptions-item label="Vue版本">v3.0.0</el-descriptions-item>
          </el-descriptions>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useUserStore } from '../../store/user'
import {
  User,
  ShoppingCart,
  Money,
  View,
  ArrowUp,
  ArrowDown
} from '@element-plus/icons-vue'

const userStore = useUserStore()
const userInfo = computed(() => userStore.getUserInfo)
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

.mt-20 {
  margin-top: 20px;
}

.welcome-card {
  margin-bottom: 20px;
}

.welcome-content {
  display: flex;
  align-items: center;
  padding: 20px 0;
}

.welcome-info {
  margin-left: 20px;
}

.welcome-info h3 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}

.welcome-info p {
  margin: 10px 0 0;
  color: #909399;
}

.data-card {
  height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
}

.data-header {
  display: flex;
  align-items: center;
}

.data-header .icon {
  font-size: 24px;
  margin-right: 10px;
  color: #409EFF;
}

.data-title {
  font-size: 16px;
  color: #606266;
}

.data-number {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin: 20px 0;
}

.data-footer {
  display: flex;
  align-items: center;
  font-size: 14px;
}

.trend {
  display: flex;
  align-items: center;
  margin-right: 8px;
}

.trend.up {
  color: #67C23A;
}

.trend.down {
  color: #F56C6C;
}

.compare {
  color: #909399;
}

.system-card {
  margin-top: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
